package Main;

import java.io.IOException;
import java.rmi.NotBoundException;
import java.sql.SQLException;
import java.util.ArrayList;
import MachineLearning.LinearRegression;
import QueryPlan.QueryPlanBuilder;
import Server.Server;

public class Main {
	
	
	public static void main(String[] args){
		try {
			LinearRegression machine = new LinearRegression(Double.parseDouble(args[6]), Double.parseDouble(args[7]));
			Server s = new Server();
			s.registerAgents(args[0]);
			QueryPlanBuilder q = new QueryPlanBuilder();
			ArrayList<String> queries = q.buildPlan(Double.parseDouble(args[1]), args[2]);
			
			int load  = Integer.parseInt(args[3]);
			ArrayList<String> transaction = new ArrayList<String>();
			while(load>1){
				transaction.addAll(queries);
				load--;
			}				
			s.dispatchQuery(args[4], transaction, Integer.parseInt(args[5]), machine);
					
		} catch (NumberFormatException e) {
			System.out.println("Falha na conversao de tipos!");
			e.printStackTrace();
		} catch (IOException e) {
			System.out.println("Falha na abertura do arquivo dado de entrada com os agentes cadastrados!");
			e.printStackTrace();
		} catch (NotBoundException e) {
			System.out.println("Falha ao acessar objeto remoto!");
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			System.out.println("Falha na abertura da conexão com o banco!");
			e.printStackTrace();
		} catch (SQLException e) {
			System.out.println("Falha na abertura da conexão com o banco!");
			e.printStackTrace();
		}
	}
}
